package cn.kongwg.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author kongwg
 * @create 2021-01-30 10:52
 */
@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        if ("root".equals(username) && "root".equals(password)) {
            System.out.println("登录成功");
            req.getSession().setAttribute("user",username);
        }else{
            System.out.println("登录失败");

            req.getRequestDispatcher("/login.jsp").forward(req,resp);
        }
    }
}
